import threading
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.embeddings import DashScopeEmbeddings


class Embedding:
    _instance = None
    _lock = threading.Lock() 
    
    def __new__(cls, *args, **kwargs):
        if cls._instance:
            return cls._instance
        with cls._lock:
            cls._instance = super().__new__(cls)
            return cls._instance
        
    def embed_query(self, text):
        pass
    
    
    def embed_documents(self, texts):
        pass

class Bge(Embedding):
    _instance = None
    _lock = threading.Lock() 
    
    def __init__(self):
        self.embedding = HuggingFaceEmbeddings(model_name='D:/models/bge-large-zh-v1.5')   
        
    def embed_query(self, text):
        return self.embedding.embed_query(text)
    
    
    def embed_documents(self, texts):
        return self.embedding.embed_documents(texts)

class DashScope(Embedding):
    _instance = None
    _lock = threading.Lock() 
    
    def __init__(self):
        self.embedding = DashScopeEmbeddings()   
        
    def embed_query(self, text):
        return self.embedding.embed_query(text)
    
    
    def embed_documents(self, texts):
        return self.embedding.embed_documents(texts)
    
# bge = Bge()
# bge.embed_query("你好")